package com.springapi.controller;

import com.springapi.entity.Goodsclass;
import com.springapi.entity.Surcharge;
import com.springapi.service.SurchargeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单附加费明细表(Surcharge)表控制层
 *
 * @author makejava
 * @since 2025-01-05 11:29:57
 */
@RestController
@RequestMapping("/api/surcharge")
public class SurchargeController {
    /**
     * 服务对象
     */
    @Resource
    private SurchargeService surchargeService;

    @GetMapping("/sumfjf")
    public Double sumfjf(@RequestParam int appid, @RequestParam int shopid, @RequestParam String  stype, @RequestParam String  name) {
        return surchargeService.sumfjf(appid,shopid,stype,name);
    }

    /**
     * 分页查询
     *
     * @param surcharge 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Surcharge>> queryByPage(Surcharge surcharge, PageRequest pageRequest) {
        return ResponseEntity.ok(this.surchargeService.queryByPage(surcharge, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Surcharge> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.surchargeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param surcharge 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Surcharge> add(Surcharge surcharge) {
        return ResponseEntity.ok(this.surchargeService.insert(surcharge));
    }

    /**
     * 编辑数据
     *
     * @param surcharge 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Surcharge> edit(Surcharge surcharge) {
        return ResponseEntity.ok(this.surchargeService.update(surcharge));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.surchargeService.deleteById(id));
    }

}

